﻿using System.Runtime.InteropServices;
using System.Xml.Linq;

namespace Lightray.Hattrick.ChppLib.EntityTypes
{
    [ComVisible(true)]
    public class LeagueLevelUnit : EntityBase
    {
        #region Properties
        
        public string LevelUnitName { get; private set; }
        public int SeasonNumber { get; private set; }
        public EntityCollection<Team> TeamsByPosition { get; internal set; }

        #endregion

        protected LeagueLevelUnit() { } 

        public static LeagueLevelUnit FromLeaugeFixturesXml(XDocument xml)
        {
            HattrickXmlReader reader = new HattrickXmlReader(xml);

            return new LeagueLevelUnit()
            {
                ID = reader.ReadNumber("LeagueLevelUnitID"),
                DataTime = reader.ReadDate("FetchedDate"),
                LevelUnitName = reader.ReadString("LeagueLevelUnitName"),
                SeasonNumber = reader.ReadNumber("Season"),
            };
        }

        public override string ToString()
        {
            return LevelUnitName;
        }
    }
}
